import { NextApiRequest, NextApiResponse } from "next";
import { initORM } from "../../../utils/orm";
import { User } from "../../../entities/User";
import { getApp, getCurrentUser, getUser } from "@/services";
import { App } from "@/entities/App";

async function getAppSecret(req: NextApiRequest, res: NextApiResponse<APIRes>) {
    const appResult = await getApp(req);
    if (!appResult.success) {
        res.status(400).json(appResult);
        return;
    }

    const app = appResult.data as App;
    res.status(200).json({
        success: true,
        data: { secret: app.secret },
        message: "Get app secret success",
    });
}

export default async function handler(
    req: NextApiRequest,
    res: NextApiResponse<APIRes>
) {
    if (req.method === "GET") {
        getAppSecret(req, res);
    } else {
        res.status(405).json({
            success: false,
            data: {},
            message: "Method not allowed",
        });
    }
}
